package xyz.xtt.asset.client.response;

import java.math.BigDecimal;
import java.util.Objects;

import org.apache.commons.lang3.StringUtils;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import xyz.xtt.asset.api.enums.DealStateEnum;
import xyz.xtt.asset.api.enums.TransactionTypeEnum;

@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
public class AssetTransactionResponse {

	// @ApiModelProperty(value = "id")
	private Long orderId;

	// @ApiModelProperty(value = "资产表ID")
	private Long assetId;

	// @ApiModelProperty(value = "卖家用户ID(业务系统)")
	private String sellerUserId;

	// @ApiModelProperty(value = "卖家区块链账户")
	private String sellerChainAccount;

	// @ApiModelProperty(value = "买家用户ID(业务系统)")
	private String buyerUserId;

	// @ApiModelProperty(value = "买家区块链账户")
	private String buyerChainAccount;

	// @ApiModelProperty(value = "交易状态0：进行中，1：完成，2：失败")
	private Integer dealState;

	// @ApiModelProperty(value = "交易区块")
	private String dealBlockNum;

	// @ApiModelProperty(value = "交易hash")
	private String dealHash;

	// @ApiModelProperty(value = "上链时间")
	private Long upChainDatetime;

	// @ApiModelProperty(value = "建立交易时间")
	private Long dealCreateDatetime;

	// @ApiModelProperty(value = "完成交易时间")
	private Long dealFinishDatetime;

	// @ApiModelProperty(value = "创建支付订单时间（支付中心）")
	private Long playCreateOrderDatetime;

	// @ApiModelProperty(value = "订单编号 会重")
	private String orderNo;

	// @ApiModelProperty(value = "交易流水号（支付中心）")
	private String tradeNo;

	// @ApiModelProperty(value = "支付状态")
	private Integer payState;

	// @ApiModelProperty(value = "支付类型0创建1加购（支付中心）")
	private Integer orderType;

	// @ApiModelProperty(value = "支付价格")
	private BigDecimal price;

	// @ApiModelProperty(value = "busId 商品id")
	private String goodsId;

	// @ApiModelProperty(value = "出售方式 0:出售1：寄售2：赠送3：拍卖")
	private Integer sellPattern;

	// @ApiModelProperty(value = "计价单价 0通宝1通钻2人民币")
	private Integer unit;

	// @ApiModelProperty(value = "出售金额")
	private BigDecimal amount;

	// @ApiModelProperty(value = "费用")
	private BigDecimal fees;

	// @ApiModelProperty(value = "订单金额")
	private BigDecimal orderPrice;

	// @ApiModelProperty(value = "实付金额")
	private BigDecimal actTotalPrice;

	@Schema(description = "业务类型　聊:liao,逛:guang,通:tong,看:kan,家:jia,资产中心:nft")
	private String bizType;

	public boolean checkCancel() {
		return Objects.equals(dealState, DealStateEnum.NOT_PAYED.code());
	}

	/**
	 * 交易双方检查
	 * 
	 * @return
	 */
	public boolean checkSide() {
		return StringUtils.isBlank(buyerUserId) && StringUtils.isBlank(sellerUserId);
	}

	public TransactionTypeEnum transactionType() {
		if (Objects.equals(buyerUserId, sellerUserId)) {
			return TransactionTypeEnum.MINT;
		}
		return TransactionTypeEnum.NORMAL;
	}

}
